<template>
<div class="box">
    <div class="title">
        给用户{{  }}添加金币
    </div>
    <div class="addDetail">
        增加金币数量：
        <input v-model="score"
        type="number"/>
    </div>
    <div class="add_btn">
        <button @click="addSCoreFun">
            添加
        </button>
    </div>
</div>
</template>

<script setup>
import {addScore} from '../api/index.js'
import {useRouter, useRoute} from 'vue-router'
import {useStore} from 'vuex'
import {ref, onMounted} from 'vue';

const store = useStore()
const router = useRouter()
const route = useRoute()
const score = ref(0)
onMounted(() => {
    let id = parseInt(route.query.user_id);
    let list = store.state.userList
    for (let i = 0;i < list.length; i++) {
        if(list[i].id == id) {
            score.value = list[i].score
        }
    }
})
const addSCoreFun= () =>  {
    let user_id = parseInt(route.query.user_id);
    console.log('user_id', user_id);
    addScore(store.state.user.token, {
        user_id, score: score.value
    }).then((t) => {
        if (t.data.code == 200) {
            alert('添加成功' + score.value)
            router.push({
                path:'/main/userList'
            })
        }
    }).catch(err=> {
        console.log(err);
    })
}
</script>

<style scoped>

</style>